<extend name="api/body" />
<block name="body">
    <div class="row">
        <div class="col-3 card" style="padding:0;margin-top:10px;">
            <div class="card-header clearfix" style="padding:5px;">
                <div class="float-left" style="line-height:30px;padding-left:0.3rem;">接口列表</div>
                <div class="float-right">
                    <a href="javascript:void(0);" class="js_close_all btn btn-sm btn-outline-primary">收起全部</a>
                    <a href="javascript:void(0);" class="js_open_all btn btn-sm btn-outline-primary">展开全部</a>
                    <button class="btn btn-sm btn-primary" data-toggle="modal" data-target="#add_module">添加模块</button>
                </div>
            </div>
            <div class="card-body" style="padding:0.5rem;">
                <div class="js_api_title api_catalog" style="overflow-y:auto;">
                    <?php
                        $api_list=[];
                        $module_num=0;
                        $api_num=0;
                        foreach($list as $v){
                            $api_data[$v['id']]=$v;
                            if($v['pid']!=0) continue;
                    ?>
                    <div>
                        <div class="js_module api_module clearfix">
                            <div class="module_title float-left">
                                <svg class="bi bi-chevron-right" width="1.2em" height="1.2em" viewBox="0 0 20 20" fill="currentColor" xmlns="http://www.w3.org/2000/svg">
                                    <path fill-rule="evenodd" d="M6.646 3.646a.5.5 0 01.708 0l6 6a.5.5 0 010 .708l-6 6a.5.5 0 01-.708-.708L12.293 10 6.646 4.354a.5.5 0 010-.708z" clip-rule="evenodd"></path>
                                </svg>
                                <?=$v['title']?>
                                <input type="hidden" class="js_module_ids" value="<?=$v['id']?>">
                            </div>
                            <div class="operate float-right">
                                <svg class="bi bi-arrow bi-arrow-down" width="1.4em" height="1.4em" viewBox="0 0 20 20" fill="currentColor" xmlns="http://www.w3.org/2000/svg">
                                    <path fill-rule="evenodd" d="M6.646 11.646a.5.5 0 01.708 0L10 14.293l2.646-2.647a.5.5 0 01.708.708l-3 3a.5.5 0 01-.708 0l-3-3a.5.5 0 010-.708z" clip-rule="evenodd"></path>
                                    <path fill-rule="evenodd" d="M10 4.5a.5.5 0 01.5.5v9a.5.5 0 01-1 0V5a.5.5 0 01.5-.5z" clip-rule="evenodd"></path>
                                </svg>
                                <svg class="bi bi-arrow bi-arrow-up" width="1.4em" height="1.4em" viewBox="0 0 20 20" fill="currentColor" xmlns="http://www.w3.org/2000/svg">
                                    <path fill-rule="evenodd" d="M10 5.5a.5.5 0 01.5.5v9a.5.5 0 01-1 0V6a.5.5 0 01.5-.5z" clip-rule="evenodd"></path>
                                    <path fill-rule="evenodd" d="M9.646 4.646a.5.5 0 01.708 0l3 3a.5.5 0 01-.708.708L10 5.707 7.354 8.354a.5.5 0 11-.708-.708l3-3z" clip-rule="evenodd"></path>
                                </svg>
                                <a href="<?=url('Api/add',['project_id'=>input('project_id'),'pid'=>$v['id']])?>">
                                    <svg class="bi bi-plus" width="1.4em" height="1.4em" viewBox="0 0 20 20" fill="currentColor" xmlns="http://www.w3.org/2000/svg">
                                        <path fill-rule="evenodd" d="M10 5.5a.5.5 0 01.5.5v4a.5.5 0 01-.5.5H6a.5.5 0 010-1h3.5V6a.5.5 0 01.5-.5z" clip-rule="evenodd"></path>
                                        <path fill-rule="evenodd" d="M9.5 10a.5.5 0 01.5-.5h4a.5.5 0 010 1h-3.5V14a.5.5 0 01-1 0v-4z" clip-rule="evenodd"></path>
                                    </svg>
                                </a>
                                <svg class="bi bi-pencil js_edit_module" data-id="<?=$v['id']?>" data-title="<?=$v['title']?>" width="1.4em" height="1.4em" viewBox="0 0 20 20" fill="currentColor" xmlns="http://www.w3.org/2000/svg">
                                    <path fill-rule="evenodd" d="M13.293 3.293a1 1 0 011.414 0l2 2a1 1 0 010 1.414l-9 9a1 1 0 01-.39.242l-3 1a1 1 0 01-1.266-1.265l1-3a1 1 0 01.242-.391l9-9zM14 4l2 2-9 9-3 1 1-3 9-9z" clip-rule="evenodd"></path>
                                    <path fill-rule="evenodd" d="M14.146 8.354l-2.5-2.5.708-.708 2.5 2.5-.708.708zM5 12v.5a.5.5 0 00.5.5H6v.5a.5.5 0 00.5.5H7v.5a.5.5 0 00.5.5H8v-1.5a.5.5 0 00-.5-.5H7v-.5a.5.5 0 00-.5-.5H5z" clip-rule="evenodd"></path>
                                </svg>
                                <svg class="bi bi-trash js_del_module" data-id="<?=$v['id']?>" width="1.4em" height="1.4em" viewBox="0 0 20 20" fill="currentColor" xmlns="http://www.w3.org/2000/svg">
                                    <path d="M7.5 7.5A.5.5 0 018 8v6a.5.5 0 01-1 0V8a.5.5 0 01.5-.5zm2.5 0a.5.5 0 01.5.5v6a.5.5 0 01-1 0V8a.5.5 0 01.5-.5zm3 .5a.5.5 0 00-1 0v6a.5.5 0 001 0V8z"></path>
                                    <path fill-rule="evenodd" d="M16.5 5a1 1 0 01-1 1H15v9a2 2 0 01-2 2H7a2 2 0 01-2-2V6h-.5a1 1 0 01-1-1V4a1 1 0 011-1H8a1 1 0 011-1h2a1 1 0 011 1h3.5a1 1 0 011 1v1zM6.118 6L6 6.059V15a1 1 0 001 1h6a1 1 0 001-1V6.059L13.882 6H6.118zM4.5 5V4h11v1h-11z" clip-rule="evenodd"></path>
                                </svg>
                            </div>
                        </div>
                        <div class="api_title">
                            <?php
                                $module_num++;
                                if(isset($v['_child'])){
                                    foreach($v['_child'] as $row){
                                        if($v['id']!=$row['pid']) continue;
                                        $api_num++;
                                        $api_list[$v['pid']][]=$row;
                            ?>
                            <div class="break_word row" style="border-bottom:1px solid #eee;">
                                <a href="#<?=$row['serial_num']?>" style="padding:5px 0;" class="col-9 ellipsis">
                                    <?=$api_num.'、'.$row['title']?>
                                    <input type="hidden" class="js_api_ids" value="<?=$row['id']?>">
                                </a>

                                <div class="operate col-3 text-right">
                                    <svg class="bi bi-arrow bi-arrow-down" width="1.4em" height="1.4em" viewBox="0 0 20 20" fill="currentColor" xmlns="http://www.w3.org/2000/svg">
                                        <path fill-rule="evenodd" d="M6.646 11.646a.5.5 0 01.708 0L10 14.293l2.646-2.647a.5.5 0 01.708.708l-3 3a.5.5 0 01-.708 0l-3-3a.5.5 0 010-.708z" clip-rule="evenodd"></path>
                                        <path fill-rule="evenodd" d="M10 4.5a.5.5 0 01.5.5v9a.5.5 0 01-1 0V5a.5.5 0 01.5-.5z" clip-rule="evenodd"></path>
                                    </svg>
                                    <svg class="bi bi-arrow bi-arrow-up" width="1.4em" height="1.4em" viewBox="0 0 20 20" fill="currentColor" xmlns="http://www.w3.org/2000/svg">
                                        <path fill-rule="evenodd" d="M10 5.5a.5.5 0 01.5.5v9a.5.5 0 01-1 0V6a.5.5 0 01.5-.5z" clip-rule="evenodd"></path>
                                        <path fill-rule="evenodd" d="M9.646 4.646a.5.5 0 01.708 0l3 3a.5.5 0 01-.708.708L10 5.707 7.354 8.354a.5.5 0 11-.708-.708l3-3z" clip-rule="evenodd"></path>
                                    </svg>
                                </div>
                            </div>
                            <?php
                                    }
                                }
                            ?>
                        </div>
                    </div>
                    <?php
                        }
                        if($module_num==0){
                    ?>
                    <div class="text-right" style="opacity:0.6;margin-right:2.2rem;">
                        <img src="__IMG__/tips/create_module.png">
                    </div>
                    <?php
                        }else if($api_num==0){
                    ?>
                    <div class="text-right" style="opacity:0.6;margin-right:2.2rem;">
                        <img src="__IMG__/tips/create_module_api.png">
                    </div>
                    <?php
                        }
                    ?>
                </div>
            </div>
        </div>
        <div class="js_api_list api_list col-9" style="padding-right:0;overflow-y:auto;margin-top:10px;">
            <?php
                $num=0;
				foreach($api_list as $v){
				    foreach($v as $row){
				        if($row['pid']==0) continue;
				        $num++;
			?>
            <div class="js_panel_box card">
                <a name="<?=$row['serial_num']?>"></a>
                <div class="card-header clearfix">
                    <div class="float-left">
                        <b><?=$num.'、'.$api_data[$row['pid']]['title'].' - '.$row['title']?></b>
                        <div class="url_info">
                            <span class="badge badge-<?=$row['request_type']=='post'?'danger':'success'?>"><?=strtoupper($row['request_type'])?></span>
                            -
                            <span style="color:#666;"><?=$project_info['project_url'].$row['api_url']?></span>
                        </div>
                    </div>
                    <div class="operate_box float-right">
                        <?php
							if(session("member_id")){
						?>
                        <a href="<?=url('Api/copy',array('ids'=>$row['id']))?>" class="btn btn-sm btn-outline-primary ajax-get">复制接口</a>
                        <a href="<?=url('Api/edit',array('ids'=>$row['id']))?>" class="btn btn-sm btn-outline-primary">修改接口</a>
                        <a href="<?=url('Api/del',array('ids'=>$row['id']))?>" class="btn btn-sm btn-danger ajax-get" tips="确定要删除该接口吗？一旦删除无法恢复">删除接口</a>
                        <?php
							}
						?>
                    </div>
                </div>
                <form class="js_api_form" action="<?=$project_info['project_url'].$row['api_url']?>" method="<?=$row['request_type']?>" target="api_result_<?=$row['id']?>">
                    <?php
    					if($row['remark']){
    				?>
                    <div class="card-body" style="padding:5px 10px;">
                        <?=str_replace("\n","<br />",$row['remark'])?>
                    </div>
                    <?php
    					}
    					$api_info=json_decode($row['api_param'],true);
    					if($api_info){
    				?>
                    <!-- Table -->
                    <table class="table">
                        <thead>
                            <tr style="background:#fcfcfc;">
                                <th style="padding:5px;padding-left:13px;" width="150">参数名称</th>
                                <th style="padding:5px;" width="100" class="text-center">参数类型</th>
                                <th style="padding:5px;" width="80" class="text-center">是否必须</th>
                                <th style="padding:5px;" width="100" class="text-center">默认值</th>
                                <th style="padding:5px;">参数说明</th>
                                <th style="padding:5px;" width="150" class="text-center">填充示例</th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php
                                foreach($api_info as $val){
                            ?>
                            <tr>
                                <td style="padding:2px;"><?=$val['name']?></td>
                                <td style="padding:2px;text-align:center;"><?=$val['type']?></td>
                                <td style="padding:2px;text-align:center;"><div style="text-align:center;color:#<?=$val['is_require']=="yes"?'f00':'999'?>;" ><?=strtoupper($val['is_require'])?></div></td>
                                <td style="padding:2px;"><?=$val['default']?></td>
                                <td style="padding:2px;"><?=$val['remark']?></td>
                                <td style="padding:2px;"><input type="<?=$val['type']?>" name="<?=$val['name']?>" style="line-height:1;padding:0.1rem 0.35rem;height:auto;" class="<?=$val['type']=="file"?'':'form-control'?>" value="<?=$val['type']=="file"?'':$val['demo']?>" placeholder="<?=$val['type']=="file"?'':'点击输入'?>"></td>
                            </tr>
                            <?php
                                }
                            ?>
                        </tbody>
                    </table>
                    <?php
                        }
                    ?>
                    <div class="nav-tabs-custom" style="margin:0;">
                        <div class="clearfix" style="background:#fcfcfc;padding:0.5rem 1rem;">
                            <div class="float-left">接口参数说明</div>
                            <div class="float-right"><button type="sbumit" class="btn btn-sm btn-primary">点击请求接口</button></div>
                        </div>
                        <div class="row">
                            <div class="js_return_param col-6" style="min-height:120px;">
                                <?php
                                    if($row['return_param']){
                                ?>
                                <pre class="break_word" style="padding-left:10px;"><?=$row['return_param']?></pre>
                                <?php
                                    }else{
                                ?>
                                <div style="text-align:center;line-height:3;color:#999;">暂无接口说明</div>
                                <?php
                                    }
                                ?>
                            </div>
                            <div class="col-6 js_api_return" style="background:#fcfcfC;overflow-y:auto;">
                                <iframe src="" class="js_frame" name="api_result_<?=$row['id']?>" style="width:100%;height:100%;border:none;"></iframe>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
            <?php
                    }
                }
                if($num==0){
            ?>
            <div class="text-center" style="padding:10rem 0;color:#999;font-weight:200;">
                <svg t="1589470977264" class="icon" viewBox="0 0 1576 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="4582" width="64" height="64"><path d="M1260.533 834.866h-134.81l9.387-15.697c6.31-11.08 9.388-23.7 9.388-37.088V168.82c0-19.698-7.849-37.858-21.237-52.016-13.389-13.388-32.318-21.237-52.016-21.237H567.093c-19.698 0-37.857 7.849-52.015 21.237-14.158 14.158-21.237 32.318-21.237 52.016v32.317h-73.253c-19.698 0-37.858 7.849-52.016 21.238-14.158 14.158-22.006 32.317-22.006 52.015v612.338c0 12.62 3.078 25.238 9.387 37.088l9.388 15.697H251.92c-5.54 0-10.31 4.77-10.31 10.31 0 2.31 0.77 5.541 3.232 7.08 1.539 1.539 4.77 3.078 7.079 3.078h533.545l54.324 54.324c5.54 5.54 14.158 9.387 22.006 9.387 7.849 0 16.62-3.078 22.007-9.387 10.31-10.311 11.85-26.008 4.77-38.627l-9.387-16.62h129.27c5.54 0 10.31-4.771 10.31-10.311s-4.77-10.311-10.31-10.311h-30.01l9.388-15.697c6.31-11.08 9.388-23.7 9.388-37.088v-32.318h263.156c5.54 0 10.31-4.77 10.31-10.31 0.154-4.156-4.616-8.157-10.156-8.157z m-283.624 52.016c0 29.086-23.7 52.785-52.785 52.785h-70.945l-73.252-74.022c-7.849-7.849-19.699-11.08-30.01-7.849l-6.309 1.54-30.778-30.78 5.54-7.078c42.628-57.556 33.856-138.657-19.699-186.056-53.554-47.245-135.579-44.167-186.055 7.079-50.477 50.476-52.786 132.347-6.31 186.825 46.475 53.555 127.73 63.096 184.363 20.468l7.08-5.54 30.778 30.778-1.54 6.31c-3.077 11.08 0 22.93 7.85 30.778l29.085 29.086H419.665c-29.086 0-52.786-23.7-52.786-52.785V273.775c0-28.317 22.93-52.016 51.247-52.016h507.537c28.316 0 51.246 23.7 51.246 52.016v613.107z m-286.086-65.404c-22.93 22.93-52.016 33.856-82.025 33.856s-59.094-11.08-82.024-33.856c-21.853-21.7-34.01-51.247-33.857-82.025 0-30.779 11.85-60.634 33.857-82.025 22.006-22.006 51.246-33.856 82.024-33.856s59.864 11.85 82.025 33.856c22.007 22.007 33.856 51.246 33.856 82.025s-11.85 60.018-33.856 82.025z m433.36-40.166c0.001 29.085-23.698 52.785-52.784 52.785h-74.022V274.544c0-19.698-7.849-37.857-21.238-52.016-13.388-13.388-32.317-21.237-52.015-21.237H514.308v-31.548c0-29.085 23.7-52.785 52.785-52.785h504.46c29.085 0 52.785 23.7 52.785 52.785v611.569zM167.436 940.436H41.397c-5.54 0-10.31 4.771-10.31 10.311 0 3.078 0.769 5.54 3.077 7.08 1.539 1.538 4.77 3.077 7.08 3.077H167.28c5.54 0 10.31-4.77 10.31-10.31s-3.846-10.158-10.156-10.158z m0 0" p-id="4583" fill="#aaa"></path><path d="M482.76 327.33h230.993c5.54 0 10.31-4.772 10.31-10.312s-4.77-10.31-10.31-10.31H482.76c-5.54 0-10.31 4.77-10.31 10.31 0 2.309 0.77 5.54 3.078 7.08 1.692 2.462 4.77 3.231 7.232 3.231z m336.563 85.102H482.76c-5.54 0-10.31 4.77-10.31 10.31 0 3.078 0.77 5.54 3.078 7.08 1.538 1.538 4.77 3.077 7.079 3.077h336.562c5.54 0 10.311-4.77 10.311-10.31 0-5.387-4.77-10.157-10.157-10.157z m-189.288 105.57H482.607c-5.54 0-10.311 4.77-10.311 10.31 0 3.078 0.77 5.54 3.078 7.08 1.539 1.539 4.77 3.077 7.079 3.077h147.429c5.54 0 10.31-4.77 10.31-10.31s-4.616-10.157-10.157-10.157zM157.278 707.905h21.237c5.54 0 10.311 4.77 10.311 10.31s-4.77 10.312-10.31 10.312h-21.238v21.237c0 5.54-4.77 10.31-10.31 10.31-3.079 0-5.54-0.769-7.08-3.077-2.308-1.54-3.078-4.771-3.078-7.08V728.68h-21.39c-5.54 0-10.311-4.77-10.311-10.31s4.77-10.311 10.31-10.311h21.237v-21.237c0-5.54 4.771-10.311 10.311-10.311s10.311 4.77 10.311 10.31v21.084z m1387.032-85.102v-21.238c0-3.231-0.77-5.54-3.078-7.079-2.308-1.539-4.77-3.078-7.079-3.078-5.54 0-10.31 4.771-10.31 10.311v21.237h-21.238c-3.077 0-5.54 0.77-7.079 3.232-1.539 2.309-3.231 4.77-3.231 7.08 0 5.54 4.77 10.31 10.31 10.31h21.238v21.237c0 5.54 4.77 10.31 10.31 10.31s10.311-4.77 10.311-10.31V643.27h21.237c5.54 0 10.311-4.77 10.311-10.31s-4.77-10.311-10.31-10.311h-21.392zM267.62 47.553h31.548c8.618 0 15.697 7.079 15.697 15.697s-7.08 15.697-15.697 15.697h-31.548v31.548c0 8.618-7.08 15.697-15.697 15.697-4.001 0-7.849-1.54-11.08-4.77-3.078-2.31-4.771-6.31-4.771-11.081V79.1h-31.548c-4.001 0-7.849-1.54-11.08-4.771-3.078-2.308-4.77-6.31-4.77-11.08 0-8.618 7.078-15.697 15.696-15.697h31.548V16.005c0-8.618 7.08-15.697 15.697-15.697s15.697 7.079 15.697 15.697v31.548zM62.634 274.544c-22.93 0-43.397 11.85-54.324 31.548-11.08 19.698-11.08 44.167 0 63.096 11.08 19.698 32.318 31.548 54.324 31.548 34.626 0 63.096-28.316 63.096-63.096s-28.47-63.096-63.096-63.096z m27.547 79.562c-5.54 9.388-15.697 15.697-27.547 15.697-17.39 0-31.548-14.158-31.548-31.548s14.158-31.547 31.548-31.547c11.08 0 21.237 6.31 27.547 15.697 5.54 9.695 5.54 21.39 0 31.701z m1275.306-205.754c-22.93 0-43.397 11.85-54.324 31.548-11.08 19.698-11.08 44.167 0 63.096 11.08 19.698 32.318 31.548 54.324 31.548 34.626 0 63.096-28.316 63.096-63.096-0.154-34.626-27.7-63.096-63.096-63.096z m27.547 78.793c-5.54 9.388-15.697 15.697-27.547 15.697-17.39 0-31.548-14.158-31.548-31.548s14.158-31.548 31.548-31.548c11.08 0 22.007 6.31 27.547 15.697 5.54 9.696 5.54 22.315 0 31.702z m0 0" p-id="4584" fill="#aaa"></path></svg>
                暂无接口，根据左侧提示开始添加接口吧
            </div>
            <?php
                }
            ?>
        </div>
    </div>
</block>
<block name="js">
    <input type="hidden" name="project_id" value="<?=$project_info['id']?>" />
    <!-- Modal -->
    <div class="modal fade" id="add_module" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title" id="exampleModalLabel">添加模块</h5>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                </div>
                <div class="modal-body">
                    <div class="form-group">
                        <label>模块名称（长度必须在2~20位之间）</label>
                        <input type="text" name="title" minlength="2" maxlength="20" value="" class="form-control" />
                    </div>
                </div>
                <div class="modal-footer">
                    <span class="js_module_tip" style="flex:1;color:#f00;"></span>
                    <button type="button" class="js_save_module btn btn-primary">保存</button>
                </div>
            </div>
        </div>
    </div>
    <script type="text/javascript" src="__PLUGIN__/sortable/sortable.min.js"></script>
    <script type="text/javascript">
        $(function(){
            $(".js_api_title").height($(window).height()-162);
            $(".js_api_list").height($(window).height()-85);
            $(window).resize(function(){
                $(".js_api_title").height($(window).height()-162);
                $(".js_api_list").height($(window).height()-85);
            })
            $(".js_return_param").each(function(){
                $(this).next().height($(this).height());
            })
            $(".js_module .module_title").on("click",function(){
                $(this).toggleClass("active");
                $(this).parent().next().toggle();
            })

            $(".js_close_all").on("click",function(){
                $(".js_module .module_title").addClass("active");
                $(".js_module .module_title").parent().next().hide();
            })
            $(".js_open_all").on("click",function(){
                $(".js_module .module_title").removeClass("active");
                $(".js_module .module_title").parent().next().show();
            })
            var module_id='';
            $(document).on("click",".js_save_module",function(){
                $(".js_module_tip").html("");
                $.post("<?=url('Api/module')?>",{id:module_id,module_title:$("input[name=title]").val(),project_id:$("input[name=project_id]").val()},function(res){
                    if(res.code==1) {
                        window.location.reload();
                    } else {
                        $(".js_module_tip").html(res.msg);
                    }
                })
            })
            $(".js_edit_module").on("click",function(){
                module_id=$(this).attr("data-id");
                $("input[name=title]").val($(this).attr("data-title"));
                $("#add_module").modal("show");
            })
            $(".js_del_module").on("click",function(){
                module_id=$(this).attr("data-id");
                $.get("<?=url('Api/delModule')?>",{module_id:module_id},function(res){
                    if(res.code==1){
                        window.location.reload();
                    }else{
                        mytips.error(res.msg);
                    }
                })
            })
            $(".api_title .bi-arrow-down").on("click",function(){
                $(this).parent().parent().next().after($(this).parent().parent());
                changeApiSort()
            })
            $(".api_title .bi-arrow-up").on("click",function(){
                $(this).parent().parent().prev().before($(this).parent().parent());
                changeApiSort()
            })

            function changeApiSort(){
                var api_ids='';
                var i=0;
                $(".js_api_ids").each(function(){
                    if(i!=0){
                        api_ids+=',';
                    }
                    api_ids+=$(this).val();
                    i++;
                })
                $.post("<?=url('Api/changeSort')?>",{api_ids:api_ids},function(res){
                    if(res.code!=1){
                        mytips.error(res.msg);
                    }
                })
            }
            $(".js_module").each(function(){
                var sortable=Sortable.create($(this).next()[0],{
                    onEnd:function(ev){
                        changeApiSort()
                    }
                });
            })
            $(".js_module .bi-arrow-down").on("click",function(){
                $(this).parent().parent().parent().next().after($(this).parent().parent().parent());
                changeModuleSort();
            })
            $(".js_module .bi-arrow-up").on("click",function(){
                $(this).parent().parent().parent().prev().before($(this).parent().parent().parent());
                changeModuleSort();
            })
            function changeModuleSort(){

                var module_ids='';
                var i=0;
                $(".js_module_ids").each(function(){
                    if(i!=0){
                        module_ids+=',';
                    }
                    module_ids+=$(this).val();
                    i++;
                })
                $.post("<?=url('Api/changeSort')?>",{api_ids:module_ids},function(res){
                    if(res.code!=1){
                        mytips.error(res.msg);
                    }
                })
            }

            $(".js_api_title").each(function(){
                var sortable=Sortable.create($(this)[0],{
                    onEnd:function(ev){
                        changeModuleSort()
                    }
                });
            })
        })
    </script>
</block>